package com.chen.controller;

import com.chen.pojo.common.PageResult;
import com.chen.pojo.dto.PolicyDto;
import com.chen.pojo.entry.Policy;
import com.chen.pojo.vo.PolicyDetailsVo;
import com.chen.service.PolicyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author chen
 * @version 1.0
 * @create_date 2025/8/22
 * 策略管理
 */
@RestController
public class PolicyController {
    @Autowired
    private PolicyService policyService;

    @GetMapping("/api/vm-service/policy/search")
    public PageResult<Policy> searchList(Integer pageIndex, Integer pageSize, String policyName) {
        return policyService.searchList(pageIndex, pageSize, policyName);
    }

    // 获取策略详情
    @GetMapping("/api/vm-service/policy/vmList/{policyId}")
    public PageResult<PolicyDetailsVo> getVmInfoByPolicyId(Integer pageIndex, Integer pageSize, @PathVariable Integer policyId) {
        return policyService.getVmInfoByPolicyId(pageIndex, pageSize, policyId);
    }

    // 修改策略
    @PutMapping("/api/vm-service/policy/{policyId}")
    public Boolean updatePolicyById(@PathVariable Integer policyId, @RequestBody PolicyDto policyDto) {
        return policyService.updatePolicyById(policyId, policyDto);
    }

    // 删除策略
    @DeleteMapping("/api/vm-service/policy/{policyId}")
    public Boolean deleteById(@PathVariable Integer policyId) {
        return policyService.deleteById(policyId);
    }

    // 新增策略
    @PostMapping("/api/vm-service/policy")
    public Boolean add(@RequestBody PolicyDto policyDto) {
        return policyService.add(policyDto);
    }

}
